﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;
using System.Reflection;
using System.Threading;
using System.IO;
using System.Diagnostics;
using ERPForms;
using System.Globalization;
using Microsoft.Reporting.WinForms;


namespace ExBug
{
    public partial class OrdonantariFrm : FrmCard
    {
        private OrdonantariRezFrm _frmNCR = null;
        private Int16 AnulCurent = 0;
        private Int16 LunaCurenta = 0;
        private String SerieNumerica = String.Empty;
        private String SerieNumericaCFP = String.Empty;
        private String CaleOPFV = String.Empty;
        private String ContAL = String.Empty;
        private int NoRecAdd = 0;
        private List<BindingSource> listBS = new List<BindingSource>();
        private List<SqlDataAdapter> listTA = new List<SqlDataAdapter>();
        private Int32 IDOrdonantare = 0;

        public OrdonantariFrm(ModuleClass mInfo, Int32 idOrdonantare = -1)
            : base(mInfo)
        {
            InitializeComponent();
            IDOrdonantare = idOrdonantare;
            HandleRezumat += new EventHandler(OrdonantariFrm_HandleRezumat);
            workConnString = mInfo.workConnectionString;
            this.HandleTiparire += new EventHandler(OrdonantariFrm_HandleTiparire);
            this.HandleAfterAdd += new AfterAddHandler(OrdonantariFrm_HandleAfterAdd);
            this.HandleBeforeAdd += new EventHandler(OrdonantariFrm_HandleBeforeAdd);

            eSRPDataSet.Ordonantari.DataDocColumn.DefaultValue = new DateTime(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
            eSRPDataSet.Ordonantari.CodUnitateColumn.DefaultValue = ModuleInfo.CodUnitate;
            eSRPDataSet.Ordonantari.AchitatColumn.DefaultValue = false;
            eSRPDataSet.Ordonantari.TotalDatoratColumn.DefaultValue = 0;
            eSRPDataSet.Ordonantari.TotalAvansuriColumn.DefaultValue = 0;
            eSRPDataSet.Ordonantari.IdModPlataColumn.DefaultValue = 1;
            eSRPDataSet.Ordonantari.VizatCFPColumn.DefaultValue = true;
            eSRPDataSet.Ordonantari.ValoareLeiColumn.DefaultValue = 0;
            eSRPDataSet.Ordonantari.MotivRefuzColumn.DefaultValue = String.Empty;
            eSRPDataSet.Ordonantari.VizatCFPColumn.DefaultValue = true;
            eSRPDataSet.Ordonantari.DataVizaCFPColumn.DefaultValue = DateTime.Now;
            eSRPDataSet.Ordonantari.ArtAlColumn.DefaultValue = String.Empty;
            eSRPDataSet.Ordonantari.IBANSursaColumn.DefaultValue = String.Empty;
            eSRPDataSet.Ordonantari.IBANDestColumn.DefaultValue = String.Empty;
            lstPK.Add(nrDocTB);
            numeMacheta = Text;
            ActiveControl = nrDocTB;
            nrDocTB.Focus();
            if (ModuleInfo.CurrentTheme == "tribunal")
            {
                tabControl1.TabPages.Remove(tabPage2);
                eSRPDataSet.Ordonantari.IDResponsabilColumn.DefaultValue = 0;
                DatoratAvansP.Visible = false;
                ValoareP.Location = new Point(ValoareP.Location.X, ValoareP.Location.Y-80);
                Height -= 80;
            }

             
        }

        void OrdonantariFrm_HandleBeforeAdd(object sender, EventArgs e)
        {
            ordonantariBindingSource.Filter = String.Empty;
            ordonantariBindingSource.Sort = String.Empty;
        }

        void OrdonantariFrm_HandleRezumat(object sender, EventArgs e)
        {
            this.ordonantariBindingSource.Sort = "[DataDoc] DESC";
            _frmNCR = new OrdonantariRezFrm(this.ordonantariBindingSource,ModuleInfo);
            _frmNCR.MdiParent = this.MdiParent;
            //_frmNCR.LunaCurenta = LunaCurenta;
            _frmNCR.SelectionAddOn = true;
            _frmNCR.Show();
        }

        void OrdonantariFrm_HandleAfterAdd(object sender, DataGridViewCellEventArgs args)
        {
            String valnew = "1", valnewCFP = "1";
            Object ret = null;
            SqlCommand cmd = new SqlCommand("", DeschideConexiune(workConnString));

            if (SerieNumerica != String.Empty)
            {
                DataRow[] retTab =eSRPDataSet.Ordonantari.Select(string.Empty,"NrDoc DESC");
                if (retTab.Length > 0)
                {
                    ESRPDataSet.OrdonantariRow rd = retTab[0] as ESRPDataSet.OrdonantariRow;
                    if (rd != null)
                        valnew = (rd.NrDoc + 1).ToString();
                }


                //cmd.CommandText = "SELECT [UltimulNrFolosit] FROM [SeriiNumerice] WHERE IDSerie='" + SerieNumerica + "' AND [CodUnitate]=" + ModuleInfo.CodUnitate.ToString();
                //ret = cmd.ExecuteScalar();
                //if (ret != null && ret != DBNull.Value)
                //{
                //    valnew = ret.ToString();
                //}
            }
            if (SerieNumericaCFP != String.Empty)
            {
                cmd.CommandText = "SELECT [UltimulNrFolosit] FROM [SeriiNumerice] WHERE IDSerie='" + SerieNumericaCFP + "' AND [CodUnitate]=" + ModuleInfo.CodUnitate.ToString();
                ret = cmd.ExecuteScalar();
                if (ret != null && ret != DBNull.Value)
                {
                    valnewCFP = ret.ToString();
                }
            }

            ///incrementarea seriei se face la salvare
            ///
            if (NoRecAdd > 0)
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "ActSeriiNumerice";
                if (SerieNumerica != String.Empty)
                {
                    cmd.Parameters.Add(new SqlParameter("IDSerie", SerieNumerica));
                    cmd.Parameters.Add(new SqlParameter("CodUnitate", ModuleInfo.CodUnitate));
                    cmd.ExecuteNonQuery();
                }
                if (SerieNumericaCFP != String.Empty)
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(new SqlParameter("IDSerie", SerieNumericaCFP));
                    cmd.Parameters.Add(new SqlParameter("CodUnitate", ModuleInfo.CodUnitate));
                    cmd.ExecuteNonQuery();
                }
                NoRecAdd--;
            }
            else
                NoRecAdd++;
            InchideConexiune(cmd.Connection);

            this.nrDocTB.Text = valnew;
            //daca e pe un tab separat nu e bine cu controlul
            ((ESRPDataSet.OrdonantariRow)((DataRowView)ordonantariBindingSource.Current).Row).NrRegCFP = valnewCFP;
            //this.nrRegCFPTB.Text = valnewCFP;
            ActiveControl = nrDocTB;

        }

        private String GetTitlu(String art)
        {
            Int16 val = Convert.ToInt16(art);
            if (val < 20)
                return "I";
            if (val >= 20 && val < 30)
                return "II";
            if (val >= 30 && val < 40)
                return "III";
            if (val >= 40 && val < 50)
                return "IV";
            if (val >= 50 && val < 51)
                return "V";
            if (val >= 51 && val < 55)
                return "VI";
            if (val >= 55 && val < 57)
                return "VII";
            if (val >= 57 && val < 59)
                return "VIII";
            if (val >= 59 && val < 71)
                return "IX";
            if (val >= 71 && val < 72)
                return "X";
            if (val >= 71 && val < 72)
                return "X";
            if (val >= 72 && val < 80)
                return "XI";
            if (val >= 80 && val < 81)
                return "XII";
            if (val >= 81 && val < 90)
                return "XIII";
            if (val >= 90)
                return "XIV";
            return "";        
        }

        void OrdonantariFrm_HandleTiparire(object sender, EventArgs e)
        {
            Salvare(this,null);

            ESRPDataSet.OrdonantariRow dr = ((ESRPDataSet.OrdonantariRow)((DataRowView)ordonantariBindingSource.Current).Row);
            if(dr==null)
                return;
            parteneriBindingSource.Find("IDPartener", dr.IDFurnizor);
            ESRPDataSet.ParteneriRow drp = ((ESRPDataSet.ParteneriRow)((DataRowView)parteneriBindingSource.Current).Row);
            if (drp == null)
                return;


            ESRPDataSet eSRPDS = new ESRPDataSet();
            Cursor.Current = Cursors.AppStarting;
            String linia1 = String.Empty, linia2 = String.Empty;
            SqlCommand cmd = new SqlCommand("", DeschideConexiune(workConnString));


            PreviewRaportFrm frm = new PreviewRaportFrm("", null,ModuleInfo);
            //eSRPDataSet - este data setul cu care lucram

            foreach (BindingSource bs in listBS)
                if (bs != null) bs.Dispose();
            listBS.Clear();
            listBS.Add(new BindingSource(eSRPDS, "BalconSetup"));

            listTA.Clear();
            listTA.Add(new SqlDataAdapter("SELECT * FROM [BalconSetup] WHERE CodUnitate=" + ModuleInfo.CodUnitate.ToString(), cmd.Connection));
            listTA[0].SelectCommand.CommandType = CommandType.Text;
            listTA[0].Fill(eSRPDS.BalconSetup);

            listTA.Add(new SqlDataAdapter("SELECT * FROM [ExBugSetup] WHERE CodUnitate=" + ModuleInfo.CodUnitate.ToString(), cmd.Connection));
            listTA[1].SelectCommand.CommandType = CommandType.Text;
            listTA[1].Fill(eSRPDS.ExBugSetup);
            listBS.Add(new BindingSource(eSRPDS, "ExBugSetup"));
            
            listTA.Add(new SqlDataAdapter("SELECT * FROM [Ordonantari] WHERE IDOrdonantare ="+dr.IdOrdonantare.ToString(), cmd.Connection));
            listTA[2].SelectCommand.CommandType = CommandType.Text;
            listTA[2].Fill(eSRPDS.Ordonantari);
            listBS.Add(new BindingSource(eSRPDS, "Ordonantari"));

            listTA.Add(new SqlDataAdapter("SELECT * FROM [Parteneri] WHERE IDPartener = " + dr.IDFurnizor.ToString(), cmd.Connection));
            listTA[3].SelectCommand.CommandType = CommandType.Text;
            listTA[3].Fill(eSRPDS.Parteneri);
            listBS.Add(new BindingSource(eSRPDS, "Parteneri"));

            listTA.Add(new SqlDataAdapter("SELECT * FROM [Banci] WHERE IDBanca = " + drp.IDBanca, cmd.Connection));
            listTA[4].SelectCommand.CommandType = CommandType.Text;
            listTA[4].Fill(eSRPDS.Banci);
            listBS.Add(new BindingSource(eSRPDS, "Banci"));

            listTA.Add(new SqlDataAdapter("SELECT * FROM [PersoaneVizaCFP] WHERE IDResponsabil = " + dr.IDResponsabil, cmd.Connection));
            listTA[5].SelectCommand.CommandType = CommandType.Text;
            listTA[5].Fill(eSRPDS.PersoaneVizaCFP);
            listBS.Add(new BindingSource(eSRPDS, "PersoaneVizaCFP"));


            String artAl = artAlCB.Text.Substring(0, 2);
            String diviziune = JurnalCB.Text + "." + GetTitlu(artAl) + "." + artAlCB.Text;


            frm.NumeRaport = "Ordonantare.rdlc";
            frm.dataloadHandler += new LoadDataHandler(frm_dataloadHandler);
            frm.drillthroughEvent += frm_drillthroughEvent;

            frm.AddDataSource("ESRPDataSet_ExBugSetup", listBS[1]);
            frm.AddDataSource("ESRPDataSet_BalconSetup", listBS[0]);
            frm.AddDataSource("ESRPDataSet_Ordonantari", listBS[2]);
            frm.AddDataSource("ESRPDataSet_Parteneri", listBS[3]);
            frm.AddDataSource("ESRPDataSet_Banci", listBS[4]);
            frm.AddDataSource("PersoaneVizaCFP", listBS[5]);
            
            frm.SetWindowFormat(true);


            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "CalcDisponibilOrd";

            cmd.Parameters.Add(new SqlParameter("Analitic", artAlCB.Text));
            cmd.Parameters.Add(new SqlParameter("PanaLa",dr["DataDoc"]));
            cmd.Parameters.Add(new SqlParameter("CodDoc",dr["IDOrdonantare"]));
            cmd.Parameters.Add(new SqlParameter("IdClasificare", dr["IDJurnal"]));
            cmd.Parameters.Add(new SqlParameter("CodUnitate", ModuleInfo.CodUnitate));
            cmd.Parameters.Add(new SqlParameter("s940", SqlDbType.Decimal,20,ParameterDirection.Output,false,20,2,String.Empty,DataRowVersion.Default,null));
            cmd.Parameters.Add(new SqlParameter("s944", SqlDbType.Decimal,20,ParameterDirection.Output,false,20,2,String.Empty,DataRowVersion.Default,null));
            cmd.Parameters.Add(new SqlParameter("s950", SqlDbType.Decimal,20,ParameterDirection.Output,false,20,2,String.Empty,DataRowVersion.Default,null));
            cmd.Parameters.Add(new SqlParameter("s960", SqlDbType.Decimal,20,ParameterDirection.Output,false,20,2,String.Empty,DataRowVersion.Default,null));
            cmd.ExecuteNonQuery();
            Decimal disp = Convert.ToDecimal(cmd.Parameters["s944"].Value), suma = Convert.ToDecimal(dr["ValoareLei"].ToString()),rest = disp-suma;
            frm.AddParameter("Diviziune",diviziune , true);
            String[] val = {disp.ToString("N2"),suma.ToString("N2"),rest.ToString("N2")};
            frm.AddParameter("Valori", val, true);
            frm.AddParameter("ControlFinanciar", (ModuleInfo.CurrentTheme!="tribunal")?"True":"False", true);


            foreach (SqlDataAdapter da in listTA)
                if (da != null) da.Dispose();
            listTA.Clear();
            frm.MdiParent = this.MdiParent;

            


            frm.Show();
            cmd.Dispose();
            StudioForm.InchideConexiune(cmd.Connection);


            Cursor.Current = Cursors.Default;
        }

        void frm_drillthroughEvent(object sender, Microsoft.Reporting.WinForms.DrillthroughEventArgs e)
        {
            if (e.ReportPath == "DisponibilOrdonantare")
            {
                //Trace.Assert(e.Parameters.Count == 1, "Numar incorect de parametrii la subraport");
                CultureInfo culture;
                DateTimeStyles styles;
                DateTime dateResult;

                culture = Application.CurrentCulture;
                styles = DateTimeStyles.None;

                ESRPDataSet.OrdonantariRow dr = ((ESRPDataSet.OrdonantariRow)((DataRowView)ordonantariBindingSource.Current).Row);
                if(dr==null)
                    return;

                SqlConnection con = DeschideConexiune(workConnString);
                this.calcDisponibilOrdRowsTableAdapter.Connection = con;
                this.calcDisponibilOrdRowsTableAdapter.Fill(this.eSRPDataSet.CalcDisponibilOrdRows, dr.IDJurnal,artAlCB.Text,dr.DataDoc,dr.IdOrdonantare,dr.CodUnitate);
               
                ((LocalReport)e.Report).DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DisponibilRows", calcDisponibilOrdRowsBindingSource));
                InchideConexiune(con);

            }
        }

        public void frm_dataloadHandler(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs args)
        {
            throw new NotImplementedException();
        }

        private void OrdonantariFrm_Load(object sender, EventArgs e)
        {
            AddBindingSource(ordonantariBindingSource);
            listTableAdaptor.Add(ordonantariTableAdapter.Adapter);

            SqlConnection con = DeschideConexiune(workConnString);
            try
            {

                this.surseFinantareTableAdapter.Connection = con;
                this.surseFinantareTableAdapter.Fill(this.eSRPDataSet.SurseFinantare);

                this.faresSetupTableAdapter.Connection = con;
                this.faresSetupTableAdapter.Fill(this.eSRPDataSet.FaresSetup, ModuleInfo.CodUnitate);
                this.persoaneVizaCFPTableAdapter.Connection = con;
                this.ordonantariTableAdapter.Connection = con;
                this.modPlataTableAdapter.Connection = con;
                this.jurnaleTableAdapter.Connection = con;
                this.articoleAliniateTableAdapter.Connection = con;
                this.parteneriTableAdapter.Connection = con;
                this.exBugSetupTableAdapter.Connection = con;
                
                this.persoaneVizaCFPTableAdapter.Fill(eSRPDataSet.PersoaneVizaCFP, ModuleInfo.CodUnitate);

                if (faresSetupBindingSource.Current != null)
                {
                    ESRPDataSet.FaresSetupRow fs = ((DataRowView)faresSetupBindingSource.Current).Row as ESRPDataSet.FaresSetupRow;
                    if (fs.ParteneriProprii)
                        this.parteneriTableAdapter.FillByUnitate(this.eSRPDataSet.Parteneri, ModuleInfo.CodUnitate);
                    else
                        this.parteneriTableAdapter.Fill(this.eSRPDataSet.Parteneri);
                }
                else
                    this.parteneriTableAdapter.FillByUnitate(this.eSRPDataSet.Parteneri,ModuleInfo.CodUnitate);
                this.articoleAliniateTableAdapter.FillByTerminal(eSRPDataSet.ArticoleAliniate, ModuleInfo.CodUnitate);
                this.jurnaleTableAdapter.Fill(eSRPDataSet.Jurnale, ModuleInfo.CodUnitate);
                this.modPlataTableAdapter.Fill(this.eSRPDataSet.ModPlata);
                this.ordonantariTableAdapter.Fill(this.eSRPDataSet.Ordonantari, ModuleInfo.CodUnitate);
                this.exBugSetupTableAdapter.Fill(this.eSRPDataSet.ExBugSetup, ModuleInfo.CodUnitate);
                LoadSetup(con);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return;
            }
            finally
            {
                InchideConexiune(con);
            }

            AddButton("Nota Contabila", global::ERPStudio.Properties.Resources._001_53, GenerareNotaContabila, ToolStripItemAlignment.Right, true);
            AddButton("Genereaza OPFV", global::ERPStudio.Properties.Resources._001_09, GenerareOPFV, ToolStripItemAlignment.Right, true);
          

            
            SetTitle();
            dataDocDTP.Format = DateTimePickerFormat.Custom;
            dataDocDTP.CustomFormat = "dd.MM.yyyy";
            dataVizaCFPDTP.Format = DateTimePickerFormat.Custom;
            dataVizaCFPDTP.CustomFormat = "dd.MM.yyyy";

            HandleSalvare += Salvare;
            if (ordonantariBindingSource.Count == 0)
                Adauga(this, null);
            else
            {
                if (IDOrdonantare != -1)
                {
                    Int32 poz = ordonantariBindingSource.Find("IdOrdonantare", IDOrdonantare);
                    if (poz != -1)
                        ordonantariBindingSource.Position = poz;
                }
            }
        }

        private void GenerareOPFV(object sender, EventArgs e)
        {
            if(ordonantariBindingSource.Current==null)
                return;
            while(((DataRowView)ordonantariBindingSource.Current).IsNew)
            {
                Salvare(sender, e);
                if (EroareSalvare)
                    return;
            }
            if (CaleOPFV == String.Empty)
            {
                MessageBox.Show("Va rugam sa completati calea spre OPFV in 'Parametrizare Modul'");
                return;
            }
            if(iDPartenerCB.SelectedItem==null)
            {
                MessageBox.Show("Va rugam selectati partenerul!");
                return;                
            }

            FrmMainMdi frm = ModuleInfo.mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("ERPForms");

            if (asm == null)
                return;


            SqlCommand cmd = new SqlCommand("SELECT * FROM [Unitati] WHERE [CodUnitate]=" + ModuleInfo.CodUnitate.ToString(),DeschideConexiune(workConnString));
            SqlDataReader udr = cmd.ExecuteReader();
            udr.Read();
            if (!udr.HasRows || (udr["CUI"].ToString().Trim() == String.Empty) || (udr["Denumire"].ToString().Trim() == String.Empty))
            {
                udr.Close();
                if (MessageBox.Show("Nu exista informatii(Denumire sau CUI) despre unitatea curenta!!\nSetam informatiile respective acum?", "Eroare", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.No)
                {
                    InchideConexiune(cmd.Connection);
                    return;
                }

                String numeClasa = "ERPForms.UnitatiInfoFrm";
                Type mModule = asm.GetType(numeClasa);

                if (mModule != null)
                {
                    FrmCard newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                        new object[] { ModuleInfo, ModuleInfo.CodUnitate }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmCard;

                    newFrm.ShowDialog();
                    udr = cmd.ExecuteReader();
                    udr.Read();
                }
            }
            String denUnit = udr["Denumire"].ToString().ToUpper();
            String adrUnit = udr["Adresa"].ToString().Replace(',', ' ').Trim();
            String udr_CUI = udr["CUI"].ToString();
            String udr_AB = udr["AgentieBancara"].ToString();
            InchideConexiune(cmd.Connection);

            CaleOPFV = CaleOPFV.Trim();
            if (CaleOPFV[CaleOPFV.Length - 1] != '\\')
                CaleOPFV += "\\";
            String FisierOrdine = CaleOPFV + "ordine.txt";
            String FisierOrdineExe = CaleOPFV + "OPFV_2010.exe";
            String[] listaLinii = null;
            String poz = String.Empty;
            int index=0,maxindex=0;
            try
            {
                listaLinii = File.ReadAllLines(FisierOrdine);
                ///afla numarul maxim
                ///
                foreach (String st in listaLinii)
                {
                    index = st.IndexOf(',');
                    if (index >= 0)
                        poz = st.Substring(0, index);
                    maxindex = Math.Max(maxindex, Convert.ToInt32(poz));
                }
                
                String[]  addLinie = new String[listaLinii.Length+1];
                listaLinii.CopyTo(addLinie, 0);
                //adaugam linia urmatoare
                maxindex++;
                ESRPDataSet.OrdonantariRow ordr = ((DataRowView)ordonantariBindingSource.Current).Row as ESRPDataSet.OrdonantariRow;
                ESRPDataSet.ParteneriRow parr = ((DataRowView)iDPartenerCB.SelectedItem).Row as ESRPDataSet.ParteneriRow;
                ESRPDataSet.JurnaleRow jurr = ((DataRowView)DenJurnalCB.SelectedItem).Row as ESRPDataSet.JurnaleRow;


                String scop = ordr.Scop.Replace(',', ' ').Trim() + " " + ordr.DocJust.Replace(',', ' ').Trim();
                String dataOP = ordr.DataDoc.Day.ToString("D2") + "/" + ordr.DataDoc.Month.ToString("D2") + "/" + ordr.DataDoc.Year.ToString();
                addLinie[listaLinii.Length] = maxindex.ToString() + "," + ordr.NrDoc.ToString() + "," + ordr.ValoareLei.ToString("F2", CultureInfo.InvariantCulture) + ","+
                    denUnit.Substring(0,Math.Min(30,denUnit.Length)) +"," + udr_CUI + "," + adrUnit.Substring(0,Math.Min(66,adrUnit.Length)) + "," + jurr.IBAN + 
                    ","  + udr_AB + "," +parr.Denumire.Substring(0,Math.Min(30,parr.Denumire.Length)) + "," + parr.CUI.ToString() + "," + parr.ContBancar.ToString() + "," +
                    ",," + scop.Substring(0,Math.Min(70,scop.Length)) + "," + dataOP
                    + ",OP";

                File.WriteAllLines(FisierOrdine,addLinie);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            udr.Close();
            InchideConexiune(cmd.Connection);
            try
            {
                //presupunem ca nu are parametrii
                ProcessStartInfo startInfo = new ProcessStartInfo(FisierOrdineExe);
                startInfo.WorkingDirectory = CaleOPFV;
                Process.Start(startInfo);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }

        private void GenerareNotaContabila(object sender, EventArgs e)
        {
            if (ordonantariBindingSource.Current == null)
                return;
            while (((DataRowView)ordonantariBindingSource.Current).IsNew)
            {
                Salvare(sender, e);
                if (EroareSalvare)
                    return;
            }

            ESRPDataSet.OrdonantariRow or = ((DataRowView)ordonantariBindingSource.Current).Row as ESRPDataSet.OrdonantariRow;
            if(or==null)
                return;

            SqlCommand cmd = new SqlCommand("exbug_OrdonantareGenNotaContabila", DeschideConexiune(workConnString));
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("idOrdonantare",or.IdOrdonantare));
            cmd.Parameters.Add(new SqlParameter("CodUnitate",ModuleInfo.CodUnitate));
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                InchideConexiune(cmd.Connection);
                MessageBoxFrm mbt = new MessageBoxFrm("Eroare", ex.Message, String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                mbt.AddButton("Iesire", 70, mbt.MessageBoxFrm_Click_Yes);
                mbt.ShowDialog();
                return;
            }
            InchideConexiune(cmd.Connection);
            MessageBoxFrm mbt1 = new MessageBoxFrm("Confirmare", "Nota contabila a fost generata cu succes!", String.Empty, MessageBoxFrm.ImaginiMB.InformareIcon, null);
            mbt1.AddButton("Iesire", 70, mbt1.MessageBoxFrm_Click_Yes);
            mbt1.ShowDialog();

            

        }


        private void furnizoriLL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            long idSel = -1;
            if (iDPartenerCB.SelectedItem != null)
            {
                ESRPDataSet.ParteneriRow parr = ((DataRowView)iDPartenerCB.SelectedItem).Row as ESRPDataSet.ParteneriRow;
                idSel = parr.IDPartener;
            }
            FrmMainMdi frm = this.MdiParent as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;
            String numeClasa = "ERPForms.ParteneriRezFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] {ModuleInfo, idSel }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                //mModule.InvokeMember("DenumirePartener", BindingFlags.SetProperty, null, newFrm, new object[] { denPartener });
                newFrm.SelectionAddOn = true;
                newFrm.ShowDialog();
                String denPartener = newFrm.currentRow.Row["Denumire"].ToString().ToUpper();
                //idPartSel = newFrm.currentRow.Row["IDPartener"].ToString();
                //incarca furnizorii
                parteneriTableAdapter.Connection = DeschideConexiune(workConnString);
                parteneriTableAdapter.Fill(eSRPDataSet.Parteneri);
                InchideConexiune(parteneriTableAdapter.Connection);
                iDPartenerCB.Text = denPartener;
            }
        }

        /// <summary>
        /// citeste setarile din ExBugSetup
        /// </summary>
        /// <param name="sqlConn"></param>
        private void LoadSetup(SqlConnection sqlConn)
        {

            /// nu a fost configurat modulul
            /// 
            while (exBugSetupBindingSource.Count==0)
            {
                MessageBoxFrm mbt = new MessageBoxFrm("Eroare", "Modulul Execuție Bugetară nu a fost configurat. \nVă rugăm să-l configurați!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                mbt.AddButton("Iesire", 70, mbt.MessageBoxFrm_Click_Yes);
                mbt.ShowDialog();
                ExBugSetupFrm frm = new ExBugSetupFrm(ModuleInfo);
                frm.ShowDialog();
                exBugSetupTableAdapter.Connection = sqlConn;
                exBugSetupTableAdapter.Fill(eSRPDataSet.ExBugSetup, ModuleInfo.CodUnitate);
            }
            ESRPDataSet.ExBugSetupRow ESRow = ((DataRowView)exBugSetupBindingSource.Current).Row as ESRPDataSet.ExBugSetupRow;

            AnulCurent = ESRow.AnulCurent;
            LunaCurenta = ESRow.LunaCurenta;

            SetInfoLunaAnul(LunaCurenta.ToString() + "," + AnulCurent.ToString());
            SerieNumerica = ESRow.IDSerieOLP;

            SerieNumericaCFP = ESRow.IDSerieCFP;

            CaleOPFV = ESRow.CaleOPFV;

            eSRPDataSet.PropunereAngajareCheltuiala.CompartimentColumn.DefaultValue = ESRow.CompartimentSpecialitate;
            eSRPDataSet.PropunereAngajareCheltuiala.OrdonatorCrediteColumn.DefaultValue = ESRow.OrdonatorCredite;
            ContAL = ESRow.ContAL;

            SqlCommand cmd = new SqlCommand("SELECT TOP 1 IDJurnal,Count(*) cate FROM [Ordonantari] where [CodUnitate]=" + ModuleInfo.CodUnitate.ToString() + " GROUP BY IDJurnal ORDER BY cate desc", sqlConn);
            Object ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                //eSRPDataSet.PropunereAngajareCheltuialaDetaliu.IDJurnalColumn.DefaultValue = Convert.ToInt32(ret);
                eSRPDataSet.Ordonantari.IDJurnalColumn.DefaultValue = Convert.ToInt32(ret);
            }

            cmd = new SqlCommand("SELECT TOP 1 o.IDResponsabil,Count(*) cate FROM [Ordonantari] o JOIN [ResponsabilVizaCFP] r on o.IDResponsabil=r.IDresponsabil  where o.[CodUnitate]=" + ModuleInfo.CodUnitate.ToString() + " GROUP BY o.IDResponsabil ORDER BY cate desc", sqlConn);
            ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                //eSRPDataSet.PropunereAngajareCheltuialaDetaliu.IDJurnalColumn.DefaultValue = Convert.ToInt32(ret);
                eSRPDataSet.Ordonantari.IDResponsabilColumn.DefaultValue = Convert.ToInt32(ret);
            }

            cmd.CommandText = "select TOP 1 [ArtAl] from [ArticoleAliniate] where [CodUnitate]=" + ModuleInfo.CodUnitate.ToString() + "  AND [Terminal]=1";
            ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                eSRPDataSet.PropunereAngajareCheltuialaDetaliu.ArtAlColumn.DefaultValue = ret.ToString();
            }
        }

        override public void Salvare(object sender, EventArgs args)
        {
            if (artAlCB.SelectedItem == null)
            {
                MessageBox.Show("Va rugam selectati articolul si alineatul din care se face plata!");
                EroareSalvare = true;
                return;            
            }

            if (DenJurnalCB.SelectedItem == null)
            {
                MessageBox.Show("Va rugam selectati capitolul din care se face plata!");
                EroareSalvare = true;
                return;
            }

            if (iDPartenerCB.SelectedItem == null)
            {
                MessageBox.Show("Va rugam selectati partenerul!");
                CancelEventArgs cargs = new CancelEventArgs();
                iDPartenerCB_Validating(sender, cargs);
                EroareSalvare = true;
                return;
            }

            if (valoareLeiNUD.Value==Decimal.Zero)
            {
                MessageBox.Show("Suma care urmeaza sa fie platita nu poate fi 0!");
                EroareSalvare = true;
                return;
            }


            ESRPDataSet.OrdonantariRow ordr = ((DataRowView)ordonantariBindingSource.Current).Row as ESRPDataSet.OrdonantariRow;
            ESRPDataSet.ParteneriRow parr = ((DataRowView)iDPartenerCB.SelectedItem).Row as ESRPDataSet.ParteneriRow;
            ESRPDataSet.JurnaleRow jurr = ((DataRowView)DenJurnalCB.SelectedItem).Row as ESRPDataSet.JurnaleRow;

            FrmMainMdi frm = ModuleInfo.mdiForm as FrmMainMdi;
            Assembly asm = frm.GetModule("ERPForms");

            while (jurr.IsIBANNull())
            {
                if (MessageBox.Show("Capitolul selectat nu are setat contul din care se face plata!\nSetam contul respectiv?", "Eroare", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
                {
                    if (asm == null)
                        return;

                    String numeClasa = "ERPForms.JurnaleFrm";
                    Type mModule = asm.GetType(numeClasa);

                    if (mModule != null)
                    {
                        FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                           new object[] { ModuleInfo, true }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;

                        //newFrm.MdiParent = frm;
                        newFrm.ShowDialog();
                        jurnaleTableAdapter.Connection = DeschideConexiune(workConnString);
                        jurnaleTableAdapter.Fill(eSRPDataSet.Jurnale, ModuleInfo.CodUnitate);
                        InchideConexiune(jurnaleTableAdapter.Connection);
                        EroareSalvare = true;
                        return;
                    }
                }
                else
                    break;
            }

            while (parr.ContBancar=="NEDEFINIT")
            {
                if (MessageBox.Show("Furnizorul selectat nu are setat contul din care se face plata!\nSetam contul respectiv?", "Eroare", MessageBoxButtons.YesNo, MessageBoxIcon.Stop) == DialogResult.Yes)
                {
                    if (asm == null)
                        return;

                    String numeClasa = "ERPForms.ConturiBancareParteneriFrm";
                    Type mModule = asm.GetType(numeClasa);

                    if (mModule != null)
                    {
                        FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                            new object[] { ModuleInfo, parr.IDPartener, parr.ContBancar, parr.IDBanca }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                        //mModule.InvokeMember("DenumirePartener", BindingFlags.SetProperty, null, newFrm, new object[] { denPartener });
                        newFrm.SelectionAddOn = true;
                        newFrm.ShowDialog();

                        parteneriTableAdapter.Connection = DeschideConexiune(workConnString);
                        parteneriTableAdapter.Fill(eSRPDataSet.Parteneri);
                        InchideConexiune(parteneriTableAdapter.Connection);
                        EroareSalvare = true;
                        return;
                    }
                }
                else
                    break;
            }

            if(ordr.IsIBANSursaNull() || ordr.IBANSursa != jurr.IBAN)
                ordr.IBANSursa = jurr.IBAN;
            if(ordr.IsIBANDestNull() || ordr.IBANDest != parr.ContBancar)
                ordr.IBANDest = parr.ContBancar;
            

            base.Salvare(this, args);
            if (EroareSalvare)
                return;
            if (SerieNumerica != String.Empty)
                if (NoRecAdd > 0)
                {
                    SqlCommand cmd = new SqlCommand("", DeschideConexiune(workConnString));
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "ActSeriiNumerice";
                    cmd.Parameters.Add(new SqlParameter("IDSerie", SerieNumerica));
                    cmd.Parameters.Add(new SqlParameter("CodUnitate", ModuleInfo.CodUnitate));
                    cmd.ExecuteNonQuery();
                    if (SerieNumericaCFP != String.Empty)
                    {
                        cmd.Parameters.Clear();
                        cmd.Parameters.Add(new SqlParameter("IDSerie", SerieNumerica));
                        cmd.Parameters.Add(new SqlParameter("CodUnitate", ModuleInfo.CodUnitate));
                        cmd.ExecuteNonQuery();
                    }
                    InchideConexiune(cmd.Connection);
                    NoRecAdd = 0;
                }
            /*String newVal = GetSum("sumaColumn").ToString("N2");
            if (this.sumaTB.Text != newVal)
                this.sumaTB.Text = newVal;*/
        }

        override public void toolStripLabelAnLuna_Click(object sender, EventArgs e)
        {
            ExBugSetupFrm frm = new ExBugSetupFrm(ModuleInfo);
            frm.ShowDialog();
            this.OnActivated(null);
            ///actualizare unitate la copi
            foreach (Form frmChild in this.MdiParent.MdiChildren)
            {
                //if (frmChild != this)
                ((StudioForm)frmChild).SetCurentMonth(ModuleInfo.CodUnitate);
            }
        }

        override public void SetCurentMonth(short vCodUnitate)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            LoadSetup(con);
            InchideConexiune(con);
        }

        private void valoareLeiNUD_Leave(object sender, EventArgs e)
        {
            if (valoareLeiNUD.Value > totalDatoratNUD.Value)
                totalDatoratNUD.Value = valoareLeiNUD.Value;
        }

        private void vizatCFPCB_CheckedChanged(object sender, EventArgs e)
        {
            motivRefuzTB.Enabled = !vizatCFPCB.Checked;
        }

        private void ContPlataLL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (iDPartenerCB.SelectedItem == null)
            {
                MessageBox.Show("Va rugam selectati partenerul!");
                return;
            }
            ESRPDataSet.ParteneriRow parr = ((DataRowView)iDPartenerCB.SelectedItem).Row as ESRPDataSet.ParteneriRow;
            FrmMainMdi frm = this.MdiParent as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;
            String numeClasa = "ERPForms.ConturiBancareParteneriFrm";
            Type mModule = asm.GetType(numeClasa);

            if (mModule != null)
            {
                FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                    new object[] {ModuleInfo,parr.IDPartener,parr.ContBancar,parr.IDBanca  }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                //mModule.InvokeMember("DenumirePartener", BindingFlags.SetProperty, null, newFrm, new object[] { denPartener });
                newFrm.SelectionAddOn = true;
                newFrm.ShowDialog();
                String newCB = mModule.InvokeMember("ContBancar", BindingFlags.GetProperty, null, newFrm, new Object[0]).ToString();
                Int16 newIDBanca = Convert.ToInt16(mModule.InvokeMember("Banca", BindingFlags.GetProperty, null, newFrm, new Object[0]));
                if(parr.ContBancar!=newCB)
                    parr.ContBancar = newCB;
                if(parr.IDBanca!=newIDBanca)
                    parr.IDBanca =newIDBanca;
                
                /*iDPartenerCB.SuspendLayout();
                int pozCur = parteneriBindingSource.Position; 
                parteneriTableAdapter.Connection = DeschideConexiune(workConnString);
                parteneriTableAdapter.Fill(eSRPDataSet.Parteneri);
                InchideConexiune(parteneriTableAdapter.Connection);
                //parteneriBindingSource.ResetCurrentItem();
                parteneriBindingSource.Position = pozCur;
                iDPartenerCB.ResumeLayout();
                 * */
            }

        }

        private void totalDatoratNUD_Enter(object sender, EventArgs e)
        {
            totalDatoratNUD.Select(0, totalDatoratNUD.ToString().Length);
        }

        private void totalAvansuriNUD_Enter(object sender, EventArgs e)
        {
            totalAvansuriNUD.Select(0, totalAvansuriNUD.ToString().Length);
        }

        private void valoareLeiNUD_Enter(object sender, EventArgs e)
        {
            valoareLeiNUD.Select(0, valoareLeiNUD.ToString().Length);
        }

        private void DenumireArtAlCB_Validating(object sender, CancelEventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            if (cb.SelectedItem == null)
            {
                MessageBox.Show("Va rugam selectati din lista articolul(clasificatia economica) pentru ordonantare!");
                e.Cancel = true;
                return;
            }
            articoleAliniateBindingSource.ResetCurrentItem();
            artAlCB.SelectedItem = DenumireArtAlCB.SelectedItem = cb.SelectedItem;
        }

        private void DenJurnalCB_Validating(object sender, CancelEventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            if (cb.SelectedItem == null)
            {
                MessageBox.Show("Va rugam selectati din lista capitolul (clasificatia functionala) pentru ordonantare!");
                e.Cancel = true;
                return;            
            }
            jurnaleBindingSource.ResetCurrentItem();
            JurnalCB.SelectedItem = DenJurnalCB.SelectedItem = cb.SelectedItem;
        }

        private void iDPartenerCB_Validating(object sender, CancelEventArgs e)
        {
            String denPartener = iDPartenerCB.Text.Trim(), idPartSel = String.Empty;
            ESRPDataSet.OrdonantariRow or = ((DataRowView)ordonantariBindingSource.Current).Row as  ESRPDataSet.OrdonantariRow;
            ESRPDataSet.ParteneriRow ors =null;
            if(iDPartenerCB.SelectedItem!=null)
                ors = ((DataRowView)iDPartenerCB.SelectedItem).Row as ESRPDataSet.ParteneriRow;
            

            if (denPartener == String.Empty || (or!=null && ors!=null && or.IDFurnizor==ors.IDPartener))
                return;
            searchPartenerBS.RemoveFilter();
            searchPartenerBS.Filter = "Denumire like '%" + denPartener + "%'";
            int nrPart = searchPartenerBS.Count;
            //iDPartenerCB.Text = denPartener;
            FrmMainMdi frm = this.MdiParent as FrmMainMdi;
            Assembly asm = frm.GetModule("erpforms");
            if (asm == null)
                return;
            if (nrPart == 1)
            {
                idPartSel = (((DataRowView)searchPartenerBS.Current).Row as ESRPDataSet.ParteneriRow).IDPartener.ToString();
            }
            if (nrPart == 0)
            {
                String numeClasa = "ERPForms.PartenerFrm";
                Type mModule = asm.GetType(numeClasa);

                if (mModule != null)
                {
                    FrmCard newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                        new object[] { ModuleInfo, false }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmCard;
                    mModule.InvokeMember("DenumirePartener", BindingFlags.SetProperty, null, newFrm, new object[] { denPartener });

                    newFrm.ShowDialog();
                    denPartener = newFrm.currentRow.Row["Denumire"].ToString().ToUpper();
                    idPartSel = newFrm.currentRow.Row["IDPartener"].ToString();
                    //incarca furnizorii
                    parteneriTableAdapter.Connection = DeschideConexiune(workConnString);
                    parteneriTableAdapter.Fill(eSRPDataSet.Parteneri);
                    InchideConexiune(parteneriTableAdapter.Connection);
                    iDPartenerCB.Text = denPartener;
                }
            }
            else
            {
                if (nrPart > 1)
                {
                    String numeClasa = "ERPForms.ParteneriRezFrm";
                    Type mModule = asm.GetType(numeClasa);

                    if (mModule != null)
                    {
                        FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                            new object[] { ModuleInfo, -1 }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                        mModule.InvokeMember("DenumirePartener", BindingFlags.SetProperty, null, newFrm, new object[] { denPartener });
                        newFrm.SelectionAddOn = true;

                        if (newFrm.ShowDialog() == DialogResult.OK)
                        {
                            iDPartenerCB.Text = newFrm.selectedRow.Cells["denumireColumn"].Value.ToString();
                        }
                        else
                        {
                            iDPartenerCB.Text = String.Empty;
                        }
                        denPartener = iDPartenerCB.Text;
                        newFrm.Close();
                        if (newFrm != null)
                            newFrm.Dispose();
                    }
                }
            }

            //}
            if (idPartSel != String.Empty)
            {
                parteneriBindingSource.Sort = "IDPartener";
                parteneriBindingSource.Position = parteneriBindingSource.Find("IDPartener", Convert.ToInt32(idPartSel));
            }
        }

        private void iDPartenerCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (iDPartenerCB.SelectedItem != null)
            {
                ESRPDataSet.ParteneriRow pr = ((DataRowView)iDPartenerCB.SelectedItem).Row as ESRPDataSet.ParteneriRow;
                ESRPDataSet.OrdonantariRow or = ((DataRowView)ordonantariBindingSource.Current).Row as ESRPDataSet.OrdonantariRow;
                if (or.IsNull("IDFurnizor") || or.IDFurnizor != pr.IDPartener)
                    or.IDFurnizor = pr.IDPartener;
            }
        }

        private void artAlCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (artAlCB.SelectedItem != null)
            {
                ESRPDataSet.ArticoleAliniateRow pr = ((DataRowView)artAlCB.SelectedItem).Row as ESRPDataSet.ArticoleAliniateRow;
                ESRPDataSet.OrdonantariRow or = ((DataRowView)ordonantariBindingSource.Current).Row as ESRPDataSet.OrdonantariRow;
                if (or.IsNull("ArtAl") || or.ArtAl != pr.ArtAl)
                    or.ArtAl = pr.ArtAl;
            }
        }

        private void JurnalCB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (JurnalCB.SelectedItem != null)
            {
                ESRPDataSet.JurnaleRow pr = ((DataRowView)JurnalCB.SelectedItem).Row as ESRPDataSet.JurnaleRow;
                ESRPDataSet.OrdonantariRow or = ((DataRowView)ordonantariBindingSource.Current).Row as ESRPDataSet.OrdonantariRow;
                if (or.IsNull("IDJurnal") || or.IDJurnal != pr.IDJurnal)
                    or.IDJurnal = pr.IDJurnal;
            }
        }

        private void RezumatOrdonantariB_Click(object sender, EventArgs e)
        {
            if (ModuleInfo.CurrentTheme == "tribunal")
            {
                FrmMainMdi frm = this.MdiParent as FrmMainMdi;
                Assembly asm = frm.GetModule("esrp");
                if (asm == null)
                    return;
                String numeClasa = "ESRP.NoteContabileRezumatFrm";
                Type mModule = asm.GetType(numeClasa);

                if (mModule != null)
                {
                    BindingSource NoteContabileBindingSource = new BindingSource();
                    NoteContabileBindingSource.DataMember = "RulajeDoc";
                    NoteContabileBindingSource.DataSource = this.eSRPDataSet;

                    SqlDataAdapter ta = new SqlDataAdapter("SELECT * FROM [RulajeDoc] WHERE CodUnitate=" + ModuleInfo.CodUnitate.ToString() + 
                        " AND IDDocument IN (SELECT IDDocument FROM [Rulaje] WHERE CodUnitate=" + ModuleInfo.CodUnitate.ToString() + " AND ([ContDebit] like '"+ContAL+
                        "%' OR [ContCredit] Like '"+ContAL+"%'))", DeschideConexiune(workConnString));

                    ta.Fill(eSRPDataSet.RulajeDoc);
                    ta.SelectCommand.CommandText = "SELECT * FROM [Rulaje] WHERE CodUnitate=" + ModuleInfo.CodUnitate.ToString();
                    ta.Fill(eSRPDataSet.Rulaje);

                    FrmRezumat newFrm = asm.CreateInstance(numeClasa, true, BindingFlags.Public | BindingFlags.Instance | BindingFlags.CreateInstance, null,
                        new object[] { NoteContabileBindingSource, ModuleInfo }, Thread.CurrentThread.CurrentCulture, new object[] { }) as FrmRezumat;
                    //mModule.InvokeMember("DenumirePartener", BindingFlags.SetProperty, null, newFrm, new object[] { denPartener });

                    newFrm.SelectionAddOn = true;
                    if (newFrm.ShowDialog() == DialogResult.OK)
                    {
                        DataRowView dr = newFrm.selectedDataRow;
                        ESRPDataSet.RulajeDocRow rd = null;
                        if (dr != null)
                        {
                            rd = dr.Row as ESRPDataSet.RulajeDocRow;
                        }

                        angLegalTB.Text = rd.NumarDoc.ToString() + "-" + rd.DataDoc.ToString("dd.MM.yyyy");
                    }
                    
                    /*denPartener = newFrm.currentRow.Row["Denumire"].ToString().ToUpper();
                    idPartSel = newFrm.currentRow.Row["IDPartener"].ToString();
                    //incarca furnizorii
                    parteneriTableAdapter.Connection = DeschideConexiune(workConnString);
                    parteneriTableAdapter.Fill(eSRPDataSet.Parteneri);
                    InchideConexiune(parteneriTableAdapter.Connection);
                    iDPartenerCB.Text = denPartener;*/
                }
                return;
            }

            ALRezFrm _frmNCR = new ALRezFrm(ModuleInfo);
            //_frmNCR.MdiParent = this.MdiParent;
            _frmNCR.ReadOnly = true;
            //_frmNCR.LunaCurenta = LunaCurenta;
            _frmNCR.SelectionAddOn = true;

            if (_frmNCR.ShowDialog() == DialogResult.OK)
            {
                angLegalTB.Text =
                        _frmNCR.selectedRow.Cells["numarColumn"].Value.ToString() + "-" + Convert.ToDateTime(_frmNCR.selectedRow.Cells["dataColumn"].Value).ToString("dd.MM.yyyy");
                
            }
        }

        private void furnizoriB_Click(object sender, EventArgs e)
        {
            furnizoriLL_LinkClicked(sender, new LinkLabelLinkClickedEventArgs(null));
        }

        private void fillToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
               
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        
       

        

        

    }
}
